#include "stdafx.h"
#include "TargetMediator.h"
#include "Enemy.h"
#include "BasicTower.h"


TargetMediator::TargetMediator(void){ m_target_list.clear(); }
TargetMediator::~TargetMediator(void){}

void TargetMediator::AddTarget(Enemy* enemy, BasicTower* basic_tower){
	m_target_list[enemy].push_back(basic_tower);
}

void TargetMediator::RemoveTower(BasicTower* basic_tower){
	for (auto it = m_target_list.begin(); it != m_target_list.end(); it++){
		for (auto it2 = m_target_list[it->first].begin(); it2 != m_target_list[it->first].end(); it2++){
			if ((*it2) == basic_tower){
				it->second.erase(it2);
				break;
			}
		}
	}
}

void TargetMediator::RemoveTarget(Enemy* enemy){
	auto it = m_target_list.find(enemy);
	if (it != m_target_list.end()){
		m_target_list.erase(it);
	}
}

Entity* TargetMediator::GetTarget(BasicTower* basic_tower){
	for (auto it = m_target_list.begin(); it != m_target_list.end(); it++){
		for (auto it2 = m_target_list[it->first].begin(); it2 != m_target_list[it->first].end(); it2++){
			if ((*it2) == basic_tower){
				return it->first;
			}
		}
	}
	return nullptr;
}

